import Vue from 'vue'
import Router from 'vue-router'

const _import = require('./_import_' + process.env.NODE_ENV)
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/
export const constantRouterMap = [
    {path: '/login', component: _import('login/index'), hidden: true},
    {path: '/404', component: _import('404'), hidden: true},

    {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
        name: '后台管理',
        meta: {title: '后台管理', icon: 'example'},
        hidden: true,
        children: [{
            path: 'dashboard',
            component: _import('dashboard/index')
        }]
    },

    {
        path: '/example',
        component: Layout,
        redirect: '/example/table',
        name: 'Example',
        meta: {title: 'Example', icon: 'example'},
        children: [
            {
                path: 'table',
                name: 'Table',
                component: _import('table/index'),
                meta: {title: 'Table', icon: 'table'}
            },
            {
                path: 'tree',
                name: 'Tree',
                component: _import('tree/index'),
                meta: {title: 'Tree', icon: 'tree'}
            },

        ]
    },
    {
        path: '/form',
        component: Layout,
        children: [
            {
                path: 'index',
                name: 'Form',
                component: _import('form/index'),
                meta: {title: 'Form', icon: 'form'}
            }
        ]
    },
    {
        path: '/news',
        component: Layout,
        redirect: '/example/table',
        name: '文章管理',
        meta: {title: '文章管理', icon: 'news'},
        children: [
            {
                path: 'post',
                name: '发布文章',
                component: _import('news/post'),
                meta: {title: '发布文章', icon: 'table'}
            },
            {
                path: 'news-module',
                name: '模块管理',
                component: _import('news/news-module'),
                meta: {title: '模块管理', icon: 'tree'}
            },
            {
                path: 'news-list',
                name: '文章列表',
                component: _import('news/news-list'),
                meta: {title: '文章列表', icon: 'tree'}
            },
            {
                path: 'news-edit/:newsId',
                name: '文章编辑',
                props: true,
                component: _import('news/news-edit'),
                hidden: true,
                meta: {title: '文章编辑'}
            }


        ]
    },
    {
        path: '/security',
        component: Layout,
        redirect: '/example/table',
        name: '安全管理',
        meta: {title: '安全管理', icon: 'table'},
        children: [
            {
                path: 'resource-manager',
                name: '资源管理',
                component: _import('security/resource-manager'),
                meta: {title: '资源管理', icon: 'table'}
            },
            {
                path: 'resource-manager-add',
                name: '添加资源',
                component: _import('security/resource-manager-add'),
                meta: {title: '添加资源', icon: 'table'},
                hidden:true
            },
            {
                path: 'resource-manager-edit/:resourceId',
                name: '添加资源',
                props:true,
                component: _import('security/resource-manager-edit'),
                meta: {title: '编辑资源', icon: 'table'},
                hidden:true
            },
            {
                path: 'role-manager',
                name: '角色管理',
                component: _import('security/role-manager'),
                meta: {title: '角色管理', icon: 'table'},
            },
            {
                path: 'role-manager-add',
                name: '角色添加',
                component: _import('security/role-manager-add'),
                meta: {title: '角色添加', icon: 'table'},
                hidden:true
            },
            {
                path: 'role-manager-edit/:roleId',
                props:true,
                name: '角色编辑',
                component: _import('security/role-manager-edit'),
                meta: {title: '角色编辑', icon: 'table'},
                hidden:true
            },
            {
                path:'role-manager-allocate/:roleId',
                props:true,
                name:'角色资源分配',
                component: _import('security/role-manager-allocate'),
                meta: {title: '角色资源分配', icon: 'table'},
                hidden:true
            },
            {
                path: 'resource-group-manager',
                name: '资源组管理',
                component: _import('security/resource-group-manager'),
                meta: {title: '资源组管理', icon: 'table'},
            },
            {
                path: 'resource-group-manager-add',
                name: '添加资源组',
                component: _import('security/resource-group-manager-add'),
                meta: {title: '添加资源组', icon: 'table'},
                hidden:true
            },
            {
                path: 'resource-group-manager-edit/:groupId',
                name: '编辑资源组',
                props:true,
                component: _import('security/resource-group-manager-edit'),
                meta: {title: '编辑资源组', icon: 'table'},
                hidden:true
            },
            {
                path: 'user-manager',
                name: '用户管理',
                component: _import('security/user-manager'),
                meta: {title: '用户管理', icon: 'table'},
            },
            {
                path: 'user-manager-add',
                hidden:true,
                name: '用户添加',
                component: _import('security/user-manager-add'),
                meta: {title: '用户添加', icon: 'table'},
            },
            {
                path: 'user-manager-edit/:username',
                hidden:true,
                props:true,
                name: '用户编辑',
                component: _import('security/user-manager-edit'),
                meta: {title: '用户编辑', icon: 'table'},
            },
        ]
    },

    {path: '*', redirect: '/404', hidden: true}
]

export default new Router({
    // mode: 'history', //后端支持可开
    scrollBehavior: () => ({y: 0}),
    routes: constantRouterMap
})

